<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>关于闭包函数的this</title>
	</head>
	<body>
		this对象是在运行时基于函数的执行环境绑定的，如果this在全局范围就是window
		如果在对象内部就指向这个对象。<br />
		而闭包却在运行时指向windo的，因为闭包并不属于这个对象的属性或方法。
	</body>
	<script>
	
		var  box={
			getThis:function(){
				return function(){
					return this;
				}
			}
		};
		alert(box.getThis()());//[object Window]
		
	/*	var  user = 'The Window';
		var boxOne ={
			user:'the boxOne',
			getUser:function(){
				return this.user;
			}
		};
		alert(boxOne.getUser());//the boxOne*/
		
		var  user = 'The Window';
		var boxOne ={
			user:'the boxOne',
			getUser:function(){
				//这里作用域的this是boxOne
			return function(){  //闭包
				//这里的作用域this是 window
				return this.user;
			}
			}
		};
		alert(boxOne.getUser()());//The Window
		
		//1使用对象冒充
		alert(boxOne.getUser().call(boxOne));//the boxOne
		
		//2作用域转换
		var  userone = 'The Window';
		var boxOne1 ={
			user:'the boxOne',
			getUser:function(){
				//这里作用域的this是boxOne
				var that =this;  
			return function(){  //闭包
				//这里的作用域this是 window
				return that.user;  //修改了this指向
			}
			}
		};
		alert(boxOne1.getUser()());//the boxOne
	</script>
</html>
